package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.mapper.SysCompanyUserRoleMapper;
import com.nineclock.system.pojo.SysCompany;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyService;
import com.nineclock.system.service.SysCompanyUserRoleService;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/company")
public class SysCompanyController {
    @Autowired
    private SysCompanyService companyService;
    @Autowired
    private SysCompanyUserService companyUserService;
    @Autowired
    private SysCompanyUserRoleService companyUserRoleService;

    @GetMapping
    public Result getCompany() {
        SysCompanyDTO company = companyService.getCompany();
        return Result.success(company);
    }

    @PostMapping("/uploadOSS")
    public Result upLoad(MultipartFile file) {
        String logoUrl = companyService.upLoadOSS(file);
        return Result.success(logoUrl);
    }

    @PutMapping
    public Result update(@RequestBody SysCompanyDTO dto) {
        companyService.updateDto(dto);
        return Result.success();
    }

    @GetMapping("/getCurrentAdmin")
    public Result getCurrentAdmin() {
        SysCompanyUserDTO currentAdmin = companyUserService.getCurrentAdmin();
        return Result.success(currentAdmin);
    }

    @PostMapping("/config/admin")
    public Result changeAdmin(@RequestBody Map<String, String> map) {
        companyUserRoleService.changeAdmin(map);
        return Result.success();
    }
}
